package dotaframework.game;

import gameframework.base.MoveStrategy;
import gameframework.base.SpeedVector;
import gameframework.base.SpeedVectorDefaultImpl;
import java.awt.Point;
import java.util.List;

public class MoveStrategyMultipleGoal implements MoveStrategy {

	List<Point> goals;
	Point currentGoal;
	Point currentPosition;

	public MoveStrategyMultipleGoal(Point pos, List<Point> goals) {
		this.goals = goals;
		currentGoal = goals.remove(0);
		this.currentPosition = pos;
	}

	public SpeedVector getSpeedVector() {
		reachNewGoal();
		double dist = currentPosition.distance(currentGoal);
		int xDirection = (int) Math.rint((currentGoal.getX() - currentPosition.getX())
				/ dist);
		int yDirection = (int) Math.rint((currentGoal.getY() - currentPosition.getY())
				/ dist);
		SpeedVector move = new SpeedVectorDefaultImpl(new Point(xDirection,
				yDirection));
		return move;
	}
	
	public void reachNewGoal() {
		double dist = currentPosition.distance(currentGoal);
		if(dist <= DotaGameImpl.SPRITE_SIZE)
			if(!goals.isEmpty())
				currentGoal = goals.remove(0);
	}
	
	public void setPosition(Point p) {
		currentPosition = p;
	}
}
